﻿using System;
using System.Web;
using System.Web.Routing;

namespace BlueSky.Web.Routing
{
    public class RouteConstraints : IRouteConstraint
    {
        protected IRouteConstraint[] _constraints = null;

        public RouteConstraints(params IRouteConstraint[] constraints)
        {
            _constraints = constraints;
        }

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            if(_constraints!=null)
                foreach (IRouteConstraint constraint in _constraints)
                {
                    if (!constraint.Match(httpContext, route, parameterName, values, routeDirection))
                        return false;
                }
            return true;
        }
    }
}
